package edu.unc.comp410.sharedcode;

/**
 * Class to represent an ordered pair of generic type
 * 
 * Either first or second may be null.
 */
public class OrderedPair<F,S> {

	private F first;
	private S second;
	
	/**
	 * Construct a new ordered pair of type <F,S>
	 * @param theFirst
	 * @param theSecond
	 */
	public OrderedPair(F theFirst, S theSecond) {
		setFirst(theFirst);
		setSecond(theSecond);
	}
	
	@Override public String toString() {
		String  firstString;
		String secondString;
		
		firstString = (first == null? "null" : first.toString());
		secondString = (second == null? "null" : second.toString());
		return new String("(" + firstString + ", " + secondString + ")"); 
	}

	
	
/*
 * Getters and setters
 */
	public F getFirst() {
		return first;
	}
	public void setFirst(F first) {
		this.first = first;
	}
	public S getSecond() {
		return second;
	}
	public void setSecond(S second) {
		this.second = second;
	}

	@Override
	public boolean equals(Object o){
		if (!(o instanceof OrderedPair)){
			return false;
		}
		OrderedPair obj = (OrderedPair) o;
		return this.getFirst().equals(obj.getFirst()) && this.getSecond().equals(obj.getSecond());
	}
	
	@Override
	public int hashCode(){
		return getFirst().hashCode() + getSecond().hashCode();
	}
	
}
